package com.atstudy.headline.web.app.mapper;

import com.atstudy.headline.entity.Categories;
import com.atstudy.headline.web.app.vo.categories.CategoryVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
* @author A
* @description 针对表【categories(内容分类表)】的数据库操作Mapper
* @createDate 2025-06-12 13:55:56
* @Entity com.atstudy.headline.entity.Categories
*/
public interface CategoriesMapper extends BaseMapper<Categories> {

    @Select("SELECT c.category_id, c.category_name, COUNT(ct.content_id) AS content_count " +
            "FROM categories c " +
            "LEFT JOIN categories child ON child.parent_id = c.category_id " +
            "LEFT JOIN contents ct ON ct.category_id IN (c.category_id, child.category_id) " +
            "AND ct.status_type = 'CONTENT_STATUS' AND ct.status_code = 3 " +
            "WHERE c.parent_id IS NULL AND c.is_active = 1 " +
            "GROUP BY c.category_id " +
            "ORDER BY c.sort_order")
    List<CategoryVO> selectActiveCategoriesWithCount();


    List<Map<String, Object>> getCategoryContentCounts();
}




